/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package aso.upna.threads;

import aso.upna.config.ClientConfig;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author triki
 */

public class ServerListenerThread implements Runnable {
    private ServerSocket sock;
    private ClientConfig conf;

    public ServerListenerThread(ClientConfig cfg)
    {
        conf = cfg;
        sock = cfg.getServerSocket();
    }

    public void run() {

        while(true)
        {
            try {
                
                System.out.println("Esperando clientes");
                Socket s = sock.accept();
                System.out.println("Cliente aceptado");
                ClientAcceptedThread hiloCli = new ClientAcceptedThread(s,conf.getPathToSharedFolder());
                Thread cliThread = new Thread(hiloCli);
                cliThread.start();
                
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

}
